#include <stdio.h>
#include "tinySH/shell.h"

void set_termio();
void reset_termio();

int main()
{
    set_termio();
    ShellEntry();
    reset_termio();
    return 0;
}

/***************************************************\
 由于Linux终端下输入字符有缓冲，必须要按Enter才能效
 所以在使用tinySH之前，关闭缓冲功能。
\***************************************************/

#include <termios.h>
#include <unistd.h>

static struct termios store_settings;

void set_termio()
{
    struct termios new_setttings;
    tcgetattr(0, &store_settings);
    new_setttings = store_settings;

    new_setttings.c_lflag &= (~ICANON);
    new_setttings.c_lflag &= (~ECHO);
    new_setttings.c_cc[VTIME] = 0;
    new_setttings.c_cc[VMIN] = 1;

    tcsetattr(0, TCSANOW, &new_setttings);
}

void reset_termio()
{
    tcsetattr(0, TCSANOW, &store_settings);
}
